#include <iostream>
#include <vector>
#include <queue>
using namespace std;

bool cmp(int a, int b)
{
	return a > b;
}

int main()
{
	int n = 0;
	cin >> n;

	//vector<int> num(n);
	priority_queue<int, vector<int>, decltype(*cmp)> pq(cmp);
	for (int i = 0, num; i < n; i++) {
		cin >> num;
		pq.push(num);
	}

	int ans = 0;
	while (pq.size() > 1) {
		int a = pq.top();
		pq.pop();
		a += pq.top();
		pq.pop();
		ans += a;
		pq.push(a);
	}
	cout << ans << endl;

	return 0;
}